import { Select } from 'antd'
import { getChannelListApi } from 'api/channel'
import React, { Component } from 'react'
const { Option } = Select

export default class Channel extends Component {
  state = {
    channels: [],
  }
  // 获取频道列表
  getChannelList = async () => {
    const res = await getChannelListApi()
    this.setState({ channels: res.channels })
  }
  render() {
    const { channels } = this.state
    const { onChange, value } = this.props
    return (
      <Select
        value={value}
        onChange={onChange}
        style={{ width: 200 }}
        placeholder="请输入频道"
      >
        {channels.map((item) => {
          return (
            <Option key={item.id} value={item.id}>
              {item.name}
            </Option>
          )
        })}
      </Select>
    )
  }
  componentDidMount() {
    this.getChannelList()
  }
}
